<template>
  <div class="collection">
    <!-- 底部导航 -->
    <bottom-nav></bottom-nav>
    <!-- 未登录 -->
    <div class="notLogin" v-if="isLogin == false">
      <div class="notLogin-title">
        <h1>新东方美食</h1>
        <h1>会做饭很酷哦~</h1>
      </div>
      <div class="notLogin-form">
        <button class="phone" @click="login()">账号密码登录</button>
        <button class="honor">华为登录</button>
      </div>
      <div class="notLogin-other">
        <div class="other-top">
          <span>其他方式登录</span>
        </div>
        <div class="other-content">
          <svg>
            <use xlink:href="#icon-weixin1"></use>
          </svg>
          <svg>
            <use xlink:href="#icon-QQ"></use>
          </svg>
          <svg>
            <use xlink:href="#icon-weibo"></use>
          </svg>
          <svg>
            <use xlink:href="#icon-shouji1"></use>
          </svg>
        </div>
      </div>
      <div class="notLogin-bottom">
        <div class="agreement">
          <input type="checkbox" :checked="checked" @click="check()" />
          <span>
            登录注册即表示同意<a>《用户协议》</a>和<a>《隐私政策》</a>
          </span>
        </div>
      </div>
    </div>

    <!-- 已登录 -->
    <div class="collection-login" v-if="isLogin == true">
      <van-tabs type="card" style="padding-top: 5px">
        <van-tab title="关注">
          <div class="collection-follow">
            <!-- 关注列表为空 -->
            <div class="followNull" v-if="followList.length == 0">
              <i class="iconfont icon-kongyemiankongneirong"></i>
              <span>关注为空</span>
            </div>
            <!-- 关注列表 -->
            <div class="follow" v-if="followList.length != 0">
              <ul>
                <li v-for="(item, index) in followList" :key="index">
                  <div class="follow-img">
                    <img :src="item.followList.user_photo" alt="" />
                  </div>
                  <div class="follow-user">
                    <div class="username">
                      <h3>{{ item.followList.nickname }}</h3>
                      <span>LV.{{ item.followList.lvl }}</span>
                    </div>
                  </div>
                  <div class="follow-follow" v-if="isFollow == false">
                    <span>关注</span>
                  </div>
                  <div class="follow-followed" v-if="isFollow == true">
                    <span>已关注</span>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </van-tab>
        <van-tab title="收藏">
          <div class="collection-content">
            <!-- 收藏列表为空 -->
            <div class="contentNull" v-if="collectionList.length == 0">
              <svg>
                <use xlink:href="#icon-shoucangweikong"></use>
              </svg>
              <span>收藏为空</span>
            </div>
            <!-- 收藏列表 -->
            <div class="content" v-if="collectionList.length != 0">
              <ul>
                <li v-for="(item, index) in collectionList" :key="index">
                  <div class="img" @click="jump(item.id)">
                    <img :src="item.collectionList.photo_path" alt="" />
                  </div>
                  <div class="right">
                    <h3>{{ item.collectionList.title }}</h3>
                    <span>
                      {{ item.collectionList.favo_counts_text }}人刚刚收藏过
                    </span>
                    <div class="user">
                      <div class="user-img">
                        <img
                          :src="item.collectionList.user.user_photo"
                          alt=""
                        />
                      </div>
                      <span>{{ item.collectionList.user.nickname }}</span>
                    </div>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import bottomNav from "../components/Nav/bottomNav.vue";
import { Toast } from "vant";
export default {
  components: {
    bottomNav,
  },
  data() {
    return {
      isLogin: false, //登录状态
      isFollow: true,
      token: "", //token值
      checked: false, //复选框的状态
      followList: [], //关注列表
      collectionList: [], //收藏列表
    };
  },
  methods: {
    //点击进行登录
    login() {
      if (this.checked == true) {
        this.$router.push("/login");
      } else {
        Toast("勾选确认用户协议和隐私政策");
      }
    },
    //点击勾选复选框
    check() {
      this.checked = true;
    },
    //跳转到菜谱详情页面
    jump(id) {
      this.id = id;
      this.$router.push({
        name: "details",
        params: {
          id: this.id,
        },
      });
    },
    //
    follow(){
      if (this.isFollow == true) {
        this.isFollow = false;
        Toast("取消关注");
      }
    },
  },
  created() {
    //从本地存储中获取token值
    this.token = JSON.parse(localStorage.getItem("token") || "[]");
    // console.log(this.token);
    //判断没有值
    if (this.token != "") {
      this.isLogin = true;
    }

    //从本地存储中获取关注列表数据
    this.followList = JSON.parse(localStorage.getItem("follow") || "[]");
    console.log("关注列表数据", this.followList);

    //从本地存储中获取收藏列表数据
    this.collectionList = JSON.parse(localStorage.getItem("collect") || "[]");
    console.log("收藏列表数据", this.collectionList);
  },
};
</script>

<style lang="less">
.collection {
  .notLogin {
    width: 100%;
    height: 612px;
    // background-image: url("https://img1.baidu.com/it/u=3635277030,1190318822&fm=26&fmt=auto");
    .notLogin-title {
      text-align: center;
      margin: 80px 15px 0px 25px;
      h1 {
        margin: 10px 5px;
      }
    }
    .notLogin-form {
      margin: 100px 0px 70px;
      .phone {
        width: 310px;
        height: 40px;
        line-height: 40px;
        font-size: 18px;
        font-weight: bold;
        border-radius: 25px;
        border: 1px solid #ffc535;
        background-color: #ffc535;
        margin: 10px 30px;
      }
      .honor {
        width: 310px;
        height: 40px;
        line-height: 40px;
        font-size: 18px;
        font-weight: bold;
        border-radius: 25px;
        border: 1px solid #f7f5f8;
        background-color: #f7f5f8;
        margin: 10px 30px;
      }
    }
    .notLogin-other {
      .other-top {
        margin: 0px 15px 0px 25px;
        span {
          font-size: 13px;
          font-weight: bold;
          color: #333;
          // color: #909090;
        }
      }
      .other-content {
        margin: 20px 15px 15px 25px;
        svg {
          width: 30px;
          height: 30px;
          margin: 0px 15px 0px 10px;
        }
      }
    }
    .notLogin-bottom {
      .agreement {
        margin: 30px 15px 0px 25px;
        display: flex;
        align-items: center;
        input {
          width: 12px;
          height: 12px;
          border-radius: 50%;
          margin: 0 5px;
        }
        span {
          font-size: 12px;
          color: #333;
          // color: #8e8e8e;
          a {
            font-weight: bold;
            // border-bottom: 1px solid #8e8e8e;
            border-bottom: 1px solid #333;
          }
        }
      }
    }
  }
  .collection-login {
    .collection-follow {
      .followNull {
        margin-top: 200px;
        display: flex;
        flex-direction: column;
        align-items: center;
        i {
          font-size: 108px;
        }
        span {
          font-size: 18px;
          color: #d7d7d7;
          margin-top: 10px;
        }
      }
      .follow {
        margin: 15px 10px 0;
        ul {
          display: flex;
          flex-direction: column;
          align-items: center;
          li {
            margin: 15px 0;
            display: flex;
            align-items: center;
            .follow-img {
              width: 35px;
              height: 35px;
              img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
              }
            }
            .follow-user {
              width: 230px;
              margin-left: 10px;
              display: flex;
              flex-direction: column;
              .username {
                font-weight: bold;
                display: flex;
                align-items: center;
                h3 {
                  font-size: 14px;
                  font-weight: bold;
                  color: #000;
                }
                span {
                  font-size: 10px;
                  color: #c48f23;
                  margin-left: 10px;
                }
              }
              .user-information {
                span {
                  font-size: 12px;
                  color: #868686;
                }
              }
            }
            .follow-follow {
              margin-right: 5px;
              span {
                width: 70px;
                height: 30px;
                font-size: 12px;
                font-weight: bold;
                color: #000;
                background-color: #fec538;
                border: 1px solid #fec538;
                border-radius: 50px;
                padding: 5px 20px;
              }
            }
            .follow-followed {
              margin-right: 5px;
              span {
                width: 70px;
                height: 30px;
                font-size: 12px;
                font-weight: bold;
                color: #000;
                background-color: #d2d2d2;
                border: 1px solid #d2d2d2;
                border-radius: 50px;
                padding: 5px 18px;
              }
            }
          }
        }
      }
    }

    .collection-content {
      .contentNull {
        margin-top: 200px;
        display: flex;
        flex-direction: column;
        align-items: center;
        svg {
          width: 190px;
          height: 108px;
        }
        span {
          font-size: 18px;
          color: #d7d7d7;
          margin-top: 10px;
        }
      }
      .content {
        ul {
          li {
            margin: 15px 15px 0;
            display: flex;
            .img {
              width: 175px;
              height: 125px;
              border-radius: 10px;
              background-color: #f3f3f3;
              img {
                width: 100%;
                height: 100%;
                border-radius: 10px;
              }
            }
            .right {
              width: 155px;
              margin-left: 10px;
              display: flex;
              flex-direction: column;
              justify-content: space-evenly;
              h3 {
                font-size: 14px;
                font-weight: bold;
              }
              span {
                font-size: 12px;
                font-weight: bold;
              }
              .user {
                display: flex;
                align-items: center;
                .user-img {
                  width: 15px;
                  height: 15px;
                  border-radius: 50%;
                  img {
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                  }
                }
                span {
                  font-size: 12px;
                  font-weight: bold;
                  color: #8e8e8e;
                  margin-left: 5px;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
